// pages/getReplied/replied.js
const app = getApp();
var util = require('../../utils/util.js')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    isGetReplied: false,
    getRepliedList: [],
    notRepliedText: "当前还没有待回复的提问",
    repliedCount: "",
    showTextReply: false
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    var index = options.index;

    var dataList = [];
    if (index == 1) {
      // 待回复的提问
      dataList = app.globalData.unansweredData;
    } else {
      // 已回复的提问
      dataList = app.globalData.repliedData;
    }

    var length = dataList.length;

    if (length == 0) {
      var notRepliedText = index == 1 ? "当前还没有待回复的提问" : "当前没有已回复的提问";
      that.setData({
        isGetReplied: true,
        notRepliedText: notRepliedText
      })

    } else {
      var list = [];
      for (var i = 0; i < length; i++) {
        var obj = {};
        var itemData = dataList[i];
        var time = itemData.createTime;
        obj['content'] = itemData.content;
        obj['createTime'] = util.crtTimeFtt(time * 1000);
        obj['remark'] = index == 1 ? "当前暂无最新回复,请耐心等待!" : itemData.remark;
        list.push(obj);
      }

      var repliedCount = index == 1 ? "当前有 " + length + " 条待回复的提问" : "当前有 " + length + " 条已回复的提问";;

      this.setData({
        repliedCount: repliedCount,
        getRepliedList: list,
        showTextReply: index == 1
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },
  //创建时间格式化显示
  crtTimeFtt: function(value) {
    var crtTime = new Date(value);
    return top.dateFtt("yyyy-MM-dd hh:mm:ss", crtTime); //直接调用公共JS里面的时间类处理的办法     
  }
})